﻿using System;
using System.Data;
using System.IO;
using System.Windows.Forms;
using HRM.HRMServiceProxy;
using WeifenLuo.WinFormsUI.Docking;
using System.Drawing;
using System.Text.RegularExpressions;
using HRM.BusinessLogic;

namespace HRM
{
    public partial class frmEmployeeList : DockContent
    {
        string _No = "";
        string _CardNo = "";
        string _IDCardNo = "";
        string _FullName = "";
        DateTime _DOBFrom = DateTime.MinValue, _DOBTo = DateTime.MinValue;
        string _POB = "";
        string _Sex = "";
        int _Standard_ID = 0;
        int _Position_ID = 0;
        int _ContractType_ID = 0;
        int _Grade_ID = 0;
        string _LCNo = "";
        string _Specialist = "";
        decimal _BasicSalaryFrom;
        decimal _BasicSalaryTo;
        string _Address = "";
        string _Job = "";
        string _BookNo = "";
        string _MedicalNo = "";

        DateTime _StartDateTo = DateTime.MinValue, _StartDateFrom = DateTime.MinValue;
        DateTime _LC_FinishDateTo = DateTime.MinValue, _LC_FinishDateFrom = DateTime.MinValue;
        DateTime _LC_BeginDateTo = DateTime.MinValue, _LC_BeginDateFrom = DateTime.MinValue;
        bool _isSearch = false;

        EmployeeClient wcfEmployee;
        BranchClient wcfBranch;
        DepartmentClient wcfDepartment;
        RoleRightInfo listRole;
        MainServiceClient wcfMain;
        LabourContractClient wcfLC;
        LabourContractInfo _LCInfo;
        DetailClient _wcfDetail;
        int itemCount = 0;
        int pageSize = UIParamater.pageSize;
        int totalPage = 0;
        int currPage = 0;
        string _OrderBy = "";
        string _OrderDirection = "";
        int employeeID = 0;
        int department_ID;
        int branch_ID;
        int _EmpID = 0;
        int _LCID = 0;
        DataSet ds = null;
        DataSet datasetForExcel = null;
        public int EmpID
        {
            get { return _EmpID; }
            set { _EmpID = value; }
        }
        bool _IsSelect = false;
        public frmEmployeeList(bool IsSelect)
        {
            InitializeComponent();
            this.DialogResult = DialogResult.Cancel;
            LoadLanguage();
            _IsSelect = IsSelect;
            wcfEmployee = Service.Employee();
            wcfBranch = Service.Branch();
            wcfDepartment = Service.Department();
            wcfMain = Service.MainService();
            wcfLC = Service.LabourContract();
            _wcfDetail = Service.Detail();

            listRole = UIParamater.Quyen_HoSoCanBo;
            if (!listRole._create)
                btnNew.Enabled = false;
            if (!listRole._update)
                btnDel.Enabled = false;
            if (!listRole.Update)
            {
                //this.btnEdit.Image = global::HRM.Properties.Resources.app;
                this.btnEdit.Text = UpdateUI.GetString("Xem");
            }
            BuildVoucherGrid();
            UISetting.LoadTreeView3(ref tvBranch);
            _isSearch = false;
            mnuSalary.Visible = false;
            //
            pager.AllowChangePageSize = true;
        }

        private void LoadLanguage()
        {
            this.TabText = this.Text = UpdateUI.GetString(this.Tag.ToString());
            UpdateUI.Load_ToolStrip(ref toolStrip2);
            UpdateUI.Load_ContextMenuStrip(ref mnuPopUp);
        }

        private void BuildVoucherGrid()
        {
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_ID", "Mã chính", "", 1, false, true);
            UISetting.AddColumn(ref dgvEmployeeList, "RowNumber", UpdateUI.GetString("stt"), "C", 40, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_Code", UpdateUI.GetString("maso"), "", 120, false, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_LastName", "hovatendem", "", 1, false, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_FirstName", "ten", "", 1, false, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_FullName", UpdateUI.GetString("hovaten"), "", 150, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_CardNo", "", "C", 80, false, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_Sex", "Giới tính", "C", 50, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_Type", "Loại nhân viên", "C", 75, false, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_DateOfBirth", UpdateUI.GetString("ngaysinh"), "C", 100, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "EMPLOYEE_SIBOOKNO", "Số sổ BH", "C", 75, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_MedicalNo", "Số thẻ BHYT", "C", 75, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Department_Name", "Phòng ban", "", 130, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Position_Name", "Chức vụ", "", 110, true, true);

            UISetting.AddColumn(ref dgvEmployeeList, "Employee_IDCardNo", UpdateUI.GetString("CMTND"), "", 80, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_IDCardIssueDate", UpdateUI.GetString("ngaycap"), "", 80, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_IDCardIssueAuthority", UpdateUI.GetString("noicap"), "", 120, true, true);

            UISetting.AddColumn(ref dgvEmployeeList, "Employee_PlaceOfBirth", UpdateUI.GetString("noisinh"), "", 120, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_Address", UpdateUI.GetString("diachi"), "", 150, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_Phone", UpdateUI.GetString("dienthoai"), "", 100, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "MaritalStatus_Name", UpdateUI.GetString("tinhtranghonnhan"), "", 150, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Religion_Name", UpdateUI.GetString("tongiao"), "", 80, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Ethnic_Name", UpdateUI.GetString("dantoc"), "", 80, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_Culture", UpdateUI.GetString("trinhdovanhoa"), "", 100, true, true);
            
            
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_BankAccountNo", UpdateUI.GetString("sotaikhoan"), "", 100, false, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_BankName", UpdateUI.GetString("nganhang"), "", 120, false, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_StartDate", UpdateUI.GetString("ngayvaocongty"), "", 120, false, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_EndDate", UpdateUI.GetString("ngaythoiviec"), "", 120, false, true);
            //UISetting.AddColumn(ref dgvEmployeeList, "Branch_Name", "Chi nhánh", "", 100, false, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Standard_Name", "Trình độ học vấn", "", 130, false, true);
        }

        private void LoadData()
        {
            //FormGlobals.App_ProgressShow(delegate()
            //{
                wcfEmployee = Service.Employee();
                if (!_isSearch)
                {
                    ds = wcfEmployee.Employee_GetList(out itemCount, branch_ID, department_ID, UISetting.GetKeyWord(txtKeyWord.Text.Trim()), _OrderBy, _OrderDirection, pager.PageIndex, pager.PageSize);
                    
                    //Lấy tất cả để xuất excel, chứ ko phân trang
                    datasetForExcel = wcfEmployee.Employee_GetList(out itemCount, branch_ID, department_ID, UISetting.GetKeyWord(txtKeyWord.Text.Trim()), _OrderBy, _OrderDirection, pager.PageIndex, itemCount);
                }
                else
                {
                    ds = wcfEmployee.Employee_GetAdvSearch(out itemCount, branch_ID, _No, _CardNo, _IDCardNo, _FullName, _DOBFrom, _DOBTo, _POB, _Sex, _Standard_ID, _Position_ID, _Grade_ID, _ContractType_ID, _Specialist, _BasicSalaryFrom, _BasicSalaryTo, _LCNo, _LC_BeginDateFrom, _LC_BeginDateTo, _LC_FinishDateFrom, _LC_FinishDateTo, _Address, _Job, _BookNo, _MedicalNo, _StartDateFrom, _StartDateTo, _OrderBy, _OrderDirection, currPage, pageSize);
                    datasetForExcel = wcfEmployee.Employee_GetAdvSearch(out itemCount, branch_ID, _No, _CardNo, _IDCardNo, _FullName, _DOBFrom, _DOBTo, _POB, _Sex, _Standard_ID, _Position_ID, _Grade_ID, _ContractType_ID, _Specialist, _BasicSalaryFrom, _BasicSalaryTo, _LCNo, _LC_BeginDateFrom, _LC_BeginDateTo, _LC_FinishDateFrom, _LC_FinishDateTo, _Address, _Job, _BookNo, _MedicalNo, _StartDateFrom, _StartDateTo, _OrderBy, _OrderDirection, currPage, itemCount);
                }
                pager.TotalRow = itemCount;

                int n = ds.Tables[0].Rows.Count;
                
                dgvEmployeeList.Rows.Clear();
                for (int i = 0; i < n; i++)
                {
                    dgvEmployeeList.Rows.Insert(i, 1);
                    dgvEmployeeList.Columns["Employee_FullName"].Frozen = true;
                    dgvEmployeeList.Rows[i].Cells["RowNumber"].Value = ds.Tables[0].Rows[i]["RowNumber"].ToString();
                    dgvEmployeeList.Rows[i].Cells["Employee_ID"].Value = ds.Tables[0].Rows[i]["Employee_ID"].ToString();
                    dgvEmployeeList.Rows[i].Cells["Employee_Code"].Value = ds.Tables[0].Rows[i]["Employee_Code"].ToString();
                    dgvEmployeeList.Rows[i].Cells["Employee_CardNo"].Value = ds.Tables[0].Rows[i]["Employee_CardNo"].ToString();
                    dgvEmployeeList.Rows[i].Cells["Employee_LastName"].Value = ds.Tables[0].Rows[i]["Employee_LastName"].ToString();
                    dgvEmployeeList.Rows[i].Cells["Employee_FirstName"].Value = ds.Tables[0].Rows[i]["Employee_FirstName"].ToString();
                    dgvEmployeeList.Rows[i].Cells["Employee_FullName"].Value = ds.Tables[0].Rows[i]["Employee_FullName"].ToString();
                    dgvEmployeeList.Rows[i].Cells["EMPLOYEE_SIBOOKNO"].Value = ds.Tables[0].Rows[i]["EMPLOYEE_SIBOOKNO"].ToString();
                    dgvEmployeeList.Rows[i].Cells["Employee_MedicalNo"].Value = ds.Tables[0].Rows[i]["Employee_MedicalNo"];

                    if (ds.Tables[0].Rows[i]["Employee_DateOfBirth"] != DBNull.Value)
                        dgvEmployeeList.Rows[i].Cells["Employee_DateOfBirth"].Value = Convert.ToDateTime(ds.Tables[0].Rows[i]["Employee_DateOfBirth"]).ToString("dd/MM/yyyy");
                    else
                        dgvEmployeeList.Rows[i].Cells["Employee_DateOfBirth"].Value = "";
                    dgvEmployeeList.Rows[i].Cells["Employee_PlaceOfBirth"].Value = ds.Tables[0].Rows[i]["Employee_PlaceOfBirth"].ToString();
                    dgvEmployeeList.Rows[i].Cells["Employee_Address"].Value = ds.Tables[0].Rows[i]["Employee_Address"].ToString();
                    dgvEmployeeList.Rows[i].Cells["Employee_Phone"].Value = ds.Tables[0].Rows[i]["Employee_Phone"].ToString();
                    dgvEmployeeList.Rows[i].Cells["Employee_Culture"].Value = ds.Tables[0].Rows[i]["Employee_Culture"].ToString();
                    dgvEmployeeList.Rows[i].Cells["Employee_Sex"].Value = ds.Tables[0].Rows[i]["Employee_Sex"].ToString();
                    dgvEmployeeList.Rows[i].Cells["Employee_Type"].Value = ds.Tables[0].Rows[i]["Employee_Type"].ToString();
                    dgvEmployeeList.Rows[i].Cells["MaritalStatus_Name"].Value = ds.Tables[0].Rows[i]["MaritalStatus_Name"].ToString();
                    dgvEmployeeList.Rows[i].Cells["Religion_Name"].Value = ds.Tables[0].Rows[i]["Religion_Name"].ToString();
                    dgvEmployeeList.Rows[i].Cells["Ethnic_Name"].Value = ds.Tables[0].Rows[i]["Ethnic_Name"].ToString();
                    dgvEmployeeList.Rows[i].Cells["Employee_IDCardNo"].Value = ds.Tables[0].Rows[i]["Employee_IDCardNo"].ToString();
                    dgvEmployeeList.Rows[i].Cells["Employee_IDCardIssueDate"].Value
                        = ds.Tables[0].Rows[i]["Employee_IDCardIssueDate"] == DBNull.Value ? ""
                        : Convert.ToDateTime(ds.Tables[0].Rows[i]["Employee_IDCardIssueDate"]).ToString("dd/MM/yyyy");
                    dgvEmployeeList.Rows[i].Cells["Employee_IDCardIssueAuthority"].Value = ds.Tables[0].Rows[i]["Employee_IDCardIssueAuthority"].ToString();
                    dgvEmployeeList.Rows[i].Cells["Employee_BankAccountNo"].Value = ds.Tables[0].Rows[i]["Employee_BankAccountNo"].ToString();
                    dgvEmployeeList.Rows[i].Cells["Employee_BankName"].Value = ds.Tables[0].Rows[i]["Employee_BankName"].ToString();
                    dgvEmployeeList.Rows[i].Cells["Employee_StartDate"].Value
                        = ds.Tables[0].Rows[i]["Employee_StartDate"] == DBNull.Value ? ""
                        : Convert.ToDateTime(ds.Tables[0].Rows[i]["Employee_StartDate"]).ToString("dd/MM/yyyy");
                    dgvEmployeeList.Rows[i].Cells["Employee_EndDate"].Value
                        = ds.Tables[0].Rows[i]["Employee_EndDate"] == DBNull.Value ? ""
                        : Convert.ToDateTime(ds.Tables[0].Rows[i]["Employee_EndDate"]).ToString("dd/MM/yyyy");

                    dgvEmployeeList.Rows[i].Cells["Position_Name"].Value = ds.Tables[0].Rows[i]["Position_Name"].ToString();
                    //dgvEmployeeList.Rows[i].Cells["Branch_Name"].Value = ds.Tables[0].Rows[i]["Branch_Name"].ToString();
                    dgvEmployeeList.Rows[i].Cells["Department_Name"].Value = ds.Tables[0].Rows[i]["Department_Name"].ToString();
                    dgvEmployeeList.Rows[i].Cells["Standard_Name"].Value = ds.Tables[0].Rows[i]["Standard_Name"].ToString();
                }
            //}, "Đang tải danh sách");
        }

        private void btnNew_Click(object sender, EventArgs e)
        {
            if (!listRole.Create)
            {
                MessageBox.Show(UpdateUI.GetString("khongcoquyenthemmoi"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            frmNhanSu f = new frmNhanSu();
            if (f.Show_Form() == System.Windows.Forms.DialogResult.OK)
            {
                pager.PageIndex = 0;
                LoadData();
            }
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedCells[0] != null)
            {
                if (listRole.Update || listRole.View)
                {

                    _EmpID = Convert.ToInt32(dgvEmployeeList.Rows[dgvEmployeeList.SelectedCells[0].RowIndex].Cells["Employee_ID"].Value);

                    frmNhanSu f = new frmNhanSu(_EmpID);
                    if (f.Show_Form() == System.Windows.Forms.DialogResult.OK)
                    {
                        pager.PageIndex = 0;
                        LoadData();
                    }
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void btnDel_Click(object sender, EventArgs e)
        {
            //if (dgvEmployeeList.SelectedCells[0] != null)
            if (dgvEmployeeList.SelectedCells.Count > 0)
            {
                if (!listRole.Delete)
                {
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxoa"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                employeeID = Convert.ToInt32(dgvEmployeeList.Rows[dgvEmployeeList.SelectedCells[0].RowIndex].Cells["Employee_ID"].Value);

                //Kiểm tra nếu số sổ đã có phát sinh trong table HRM_BHDetail thì không cho xóa
                if (_wcfDetail.Detail_CheckExistSIBookNo(Convert.ToString(dgvEmployeeList.Rows[dgvEmployeeList.SelectedCells[0].RowIndex].Cells["EMPLOYEE_SIBOOKNO"].Value), Program.strBranchCode))
                {
                    MessageBox.Show("Nhân sự này đã đóng BHXH, bạn hãy chuyển sang trạng thái thôi việc!", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (wcfEmployee.Employee_Using(employeeID) == 0)
                {
                    if (MessageBox.Show(UpdateUI.GetString("bancochacchanxoa"), UIParamater.TitleProject, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        if (wcfEmployee.Employee_Delete(employeeID))
                        {
                            Program.taskbarNotifier.Show(UIParamater.TitleProject, UpdateUI.GetString("xoathanhcong"), UIParamater.TIME_MOVE_UP, UIParamater.TIME_SHOW, UIParamater.TIME_MOVE_DOWN);
                            //
                            pager.PageIndex = 0;
                            LoadData();
                        }
                        else
                        {
                            MessageBox.Show(UpdateUI.GetString("xoakhongthanhcong"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }
                else
                {
                    MessageBox.Show(UpdateUI.GetString("dasudung"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

            }
        }

        private void frmEmployeeList_KeyUp(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Escape:
                    this.Dispose();
                    this.Close();
                    break;
                case Keys.F2:
                    btnNew_Click(null, null);
                    break;
                case Keys.F3:
                    btnEdit_Click(null, null);
                    break;
            }
        }

        private void btnEmployee_Contract_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedRows.Count > 0)
            {
                employeeID = Convert.ToInt32(dgvEmployeeList.SelectedRows[0].Cells["Employee_ID"].Value);
                Form f = new frmLabourContractInfo(0, employeeID, listRole);
                if (f.ShowDialog(this) == DialogResult.OK)
                {
                    pager.PageIndex = 0;
                    LoadData();
                }
            }
            else
                MessageBox.Show(UpdateUI.GetString("chuachonnhanvien"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);

        }

        private void dgvEmployeeList_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                _EmpID = Convert.ToInt32(dgvEmployeeList.Rows[dgvEmployeeList.SelectedCells[0].RowIndex].Cells["Employee_ID"].Value);
                this.DialogResult = DialogResult.OK;
                btnEdit_Click(null, null);
            }
        }

        private void dgvEmployeeList_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (tvBranch.Nodes.Count > 0)
                {
                    if (dgvEmployeeList.Rows.Count > 0)
                    {
                        mnuPrintCard.Enabled = true;
                        btnNewPopUp.Enabled = true;
                        mnuAward.Enabled = true;
                        mnuDeclaration.Enabled = true;
                        btnEditPopUp.Enabled = true;
                        btnDeletePopUp.Enabled = true;
                        mnuQDTangluong.Enabled = true;
                        mnuIncreaseSalary.Enabled = true;
                        mnuFurlough.Enabled = true;
                        mnuOffered.Enabled = true;
                        mnuComment.Enabled = true;
                        mnuPrintSalaryDepartment.Enabled = true;
                    }
                    else
                    {
                        mnuPrintCard.Enabled = false;
                        btnNewPopUp.Enabled = true;
                        mnuAward.Enabled = false;
                        mnuDeclaration.Enabled = false;
                        btnEditPopUp.Enabled = false;
                        btnDeletePopUp.Enabled = false;
                        mnuQDTangluong.Enabled = false;
                        mnuIncreaseSalary.Enabled = false;
                        mnuFurlough.Enabled = false;
                        mnuOffered.Enabled = false;
                        mnuComment.Enabled = false;
                        mnuPrintSalaryDepartment.Enabled = false;
                    }

                }
            }
        }

        private void btnNewPopUp_Click(object sender, EventArgs e)
        {
            btnNew_Click(null, null);
        }

        private void btnEditPopUp_Click(object sender, EventArgs e)
        {
            btnEdit_Click(null, null);
        }

        private void btnDeletePopUp_Click(object sender, EventArgs e)
        {
            btnDel_Click(null, null);
        }

        private void mnuSoanHDLD_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedRows.Count > 0)
            {
                if (listRole.Update || listRole.View)
                {
                    employeeID = Convert.ToInt32(dgvEmployeeList.CurrentRow.Cells["Employee_ID"].Value);
                    frmPreviewReport f = new frmPreviewReport("ContractTemplate", new string[] { employeeID.ToString() });
                    f.Show(this);
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void mnuQDNghiHuongBHXH_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedCells[0] != null)
            {
                if (listRole.Update || listRole.View)
                {
                    employeeID = Convert.ToInt32(dgvEmployeeList.Rows[dgvEmployeeList.SelectedCells[0].RowIndex].Cells["Employee_ID"].Value);
                    frmPreviewReport f = new frmPreviewReport("QDTangLuong", new string[] { employeeID.ToString() });
                    f.Show(DockPanel);
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void tvBranch_AfterSelect(object sender, TreeViewEventArgs e)
        {
            txtKeyWord.Text = "";
            _isSearch = false;
            DataTable dt = new DataTable();
            if (e.Node.Level == 0)
            {
                if (Program.isAdmin || Program.isViewAll)
                    branch_ID = 0;
                else
                    branch_ID = Program.intBranchID;
                department_ID = 0;
                pager.PageIndex = 0;
                LoadData();
            }
            else if (e.Node.Level == 1)
            {
                branch_ID = Convert.ToInt32(e.Node.Tag);
                department_ID = 0;
                pager.PageIndex = 0;
                LoadData();
            }
            else if (e.Node.Level >= 2)
            {
                department_ID = Convert.ToInt32(e.Node.Tag);
                branch_ID = Convert.ToInt32(e.Node.Parent.Tag);
                pager.PageIndex = 0;
                LoadData();
            }
        }

        private void mnuIncreaseSalary_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedCells[0] != null)
            {
                if (listRole.Update || listRole.View)
                {
                    employeeID = Convert.ToInt32(dgvEmployeeList.Rows[dgvEmployeeList.SelectedCells[0].RowIndex].Cells["Employee_ID"].Value);
                    frmPositionDetailsInfo f = new frmPositionDetailsInfo(0, employeeID, listRole);
                    if (f.ShowDialog(this) == DialogResult.OK)
                        LoadData();
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void mnuFurlough_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedCells[0] != null)
            {
                if (listRole.Update || listRole.View)
                {
                    employeeID = Convert.ToInt32(dgvEmployeeList.Rows[dgvEmployeeList.SelectedCells[0].RowIndex].Cells["Employee_ID"].Value);
                    frmLeaveWorkInfo f = new frmLeaveWorkInfo(0, employeeID, listRole);
                    if (f.ShowDialog(this) == DialogResult.OK)
                        LoadData();
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void mnuOffered_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedCells[0] != null)
            {
                if (listRole.Update || listRole.View)
                {
                    employeeID = Convert.ToInt32(dgvEmployeeList.Rows[dgvEmployeeList.SelectedCells[0].RowIndex].Cells["Employee_ID"].Value);
                    RoleRightInfo _lRole = UIParamater.Quyen_DeNghiTroCap;

                    frmOfferedInfo f = new frmOfferedInfo(0, _lRole, employeeID);
                    if (f.ShowDialog(this) == DialogResult.OK)
                        LoadData();
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void txtKeyWord_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                btnFind_Click(null, null);
        }

        private void btnFind_Click(object sender, EventArgs e)
        {
            pager.PageIndex = 0;
            _isSearch = false;
            LoadData();

        }

        private void mnuDeclaration_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedCells[0] != null)
            {
                if (listRole.Update || listRole.View)
                {
                    employeeID = Convert.ToInt32(dgvEmployeeList.Rows[dgvEmployeeList.SelectedCells[0].RowIndex].Cells["Employee_ID"].Value);
                    string SoBHXH = dgvEmployeeList.Rows[dgvEmployeeList.SelectedCells[0].RowIndex].Cells["EMPLOYEE_SIBOOKNO"].Value.ToString();
                    frmPreviewReport f = new frmPreviewReport("BHXHMau07", new string[] { employeeID.ToString(), null, null, SoBHXH });
                    f.Show(this);
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void mnuQDTangLuong_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedRows.Count > 0)
            {
                if (listRole.Update || listRole.View)
                {
                    employeeID = Convert.ToInt32(dgvEmployeeList.SelectedRows[0].Cells["Employee_ID"].Value);
                    frmPreviewReport f = new frmPreviewReport("QDTangLuong", new string[] { employeeID.ToString() });
                    f.Show(this);
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void mnuComment_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedCells[0] != null)
            {
                if (listRole.Update || listRole.View)
                {
                    employeeID = Convert.ToInt32(dgvEmployeeList.Rows[dgvEmployeeList.SelectedCells[0].RowIndex].Cells["Employee_ID"].Value);
                    RoleRightInfo _lRole = UIParamater.Quyen_HoSoCanBo;

                    frmCommentInfo f = new frmCommentInfo(0, employeeID, _lRole);
                    if (f.ShowDialog(this) == DialogResult.OK)
                        LoadData();
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void mnuCurriculumVitae_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedRows.Count > 0)
            {
                employeeID = Convert.ToInt32(dgvEmployeeList.SelectedRows[0].Cells["Employee_ID"].Value);
                if (listRole.Update || listRole.View)
                {
                    frmPreviewReport f = new frmPreviewReport("SYLL", new string[] { employeeID.ToString() });
                    f.Show(this);
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void frmEmployeeList_Activated(object sender, EventArgs e)
        {
            LoadLanguage();
            if (dgvEmployeeList.Columns.Count > 0)
            {

                dgvEmployeeList.Columns["RowNumber"].HeaderText = UpdateUI.GetString("stt");

                dgvEmployeeList.Columns["Employee_Code"].HeaderText = UpdateUI.GetString("maso");
                dgvEmployeeList.Columns["Employee_CardNo"].HeaderText = UpdateUI.GetString("sothe");
                dgvEmployeeList.Columns["Employee_FullName"].HeaderText = UpdateUI.GetString("hovaten");
                dgvEmployeeList.Columns["Employee_DateOfBirth"].HeaderText = UpdateUI.GetString("ngaysinh");
                dgvEmployeeList.Columns["Employee_PlaceOfBirth"].HeaderText = UpdateUI.GetString("noisinh");
                dgvEmployeeList.Columns["Employee_Address"].HeaderText = UpdateUI.GetString("diachi");
                dgvEmployeeList.Columns["Employee_Phone"].HeaderText = UpdateUI.GetString("dienthoai");
                dgvEmployeeList.Columns["Employee_Sex"].HeaderText = "GT";
                dgvEmployeeList.Columns["MaritalStatus_Name"].HeaderText = UpdateUI.GetString("tinhtranghonnhan");
                dgvEmployeeList.Columns["Religion_Name"].HeaderText = UpdateUI.GetString("tongiao");
                dgvEmployeeList.Columns["Ethnic_Name"].HeaderText = UpdateUI.GetString("dantoc");
                dgvEmployeeList.Columns["Employee_Culture"].HeaderText = "Trình độ VH";
                dgvEmployeeList.Columns["Employee_IDCardNo"].HeaderText = UpdateUI.GetString("CMTND");
                dgvEmployeeList.Columns["Employee_IDCardIssueDate"].HeaderText = UpdateUI.GetString("ngaycap");
                dgvEmployeeList.Columns["Employee_IDCardIssueAuthority"].HeaderText = UpdateUI.GetString("noicap");
                dgvEmployeeList.Columns["Employee_BankAccountNo"].HeaderText = UpdateUI.GetString("sotaikhoan");
                dgvEmployeeList.Columns["Employee_BankName"].HeaderText = UpdateUI.GetString("nganhang");
                dgvEmployeeList.Columns["Employee_StartDate"].HeaderText = UpdateUI.GetString("ngayvaocongty");
                dgvEmployeeList.Columns["Employee_EndDate"].HeaderText = UpdateUI.GetString("ngayketthuc");
                dgvEmployeeList.Columns["Position_Name"].HeaderText = UpdateUI.GetString("chucvu");
                //dgvEmployeeList.Columns["Branch_Name"].HeaderText = UpdateUI.GetString("chinhanh");
                dgvEmployeeList.Columns["Department_Name"].HeaderText = UpdateUI.GetString("phongban");
                dgvEmployeeList.Columns["Standard_Name"].HeaderText = UpdateUI.GetString("trinhdo");
            }
        }

        private void frmEmployeeList_FormClosing(object sender, FormClosingEventArgs e)
        {
            wcfEmployee.Close();
            wcfBranch.Close();
            wcfDepartment.Close();
            wcfMain.Close();
        }

        private void mnuAward_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedCells[0] != null)
            {
                if (listRole.Update || listRole.View)
                {
                    employeeID = Convert.ToInt32(dgvEmployeeList.Rows[dgvEmployeeList.SelectedCells[0].RowIndex].Cells["Employee_ID"].Value);
                    RoleRightInfo _lRole = UIParamater.Quyen_HoSoCanBo;

                    frmAwardInfo f = new frmAwardInfo(0, employeeID);
                    if (f.ShowDialog(this) == DialogResult.OK)
                        LoadData();
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }


        #region Print Card



        private void btnPrint_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedCells[0] != null)
            {
                employeeID = Convert.ToInt32(dgvEmployeeList.Rows[dgvEmployeeList.SelectedCells[0].RowIndex].Cells["Employee_ID"].Value);

                if (employeeID > 0)
                {
                    //Xem trước khi in
                    frmPrintCard f = new frmPrintCard(employeeID);
                    f.ShowDialog(this);
                }
            }
        }

        #endregion

        private void dgvEmployeeList_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            _OrderBy = dgvEmployeeList.SortedColumn.Name;
            switch (dgvEmployeeList.SortOrder.ToString())
            {
                case "Ascending":
                    _OrderDirection = "ASC";
                    break;
                case "Descending":
                    _OrderDirection = "DESC";
                    break;
            }
            LoadData();
        }

        private void btnExcel_Click(object sender, EventArgs e)
        {
            BranchClient wcfBranch = Service.Branch();
            DepartmentClient wcfDept = Service.Department();
            string branchName = "Tất cả";
            string departmentName = "Tất cả";
            string _Cre = "";
            DataTable dt = new DataTable();
            string fileName = "DSNV ";
            if (branch_ID > 0)
            {
                branchName = wcfBranch.Branch_GetInfo(branch_ID).Name;
                fileName += branchName;
            }
            if (department_ID > 0)
            {
                departmentName = wcfDepartment.Department_GetInfo(department_ID).Name;
                fileName += " (" + departmentName + ")";
            }
            fileName += "-" + DateTime.Now.ToString("ddMMyyyy") + ".xls";

            frmFieldExcel f = new frmFieldExcel(listRole, true);
            if (f.ShowDialog(this) == DialogResult.OK)
            {
                _Cre = f.Filed;
                string[] _ArrayCre = null;
                _ArrayCre = _Cre.Split(new char[] { ',' });
                //
                dt = datasetForExcel.Tables[0].DefaultView.ToTable(false, _ArrayCre);

                //
                try
                {
                    if (dt.Rows.Count > 0)
                    {
                        ExportData2Excel("DANH SÁCH NHÂN VIÊN", dt, Path.GetTempPath() + "\\" + fileName);
                        try
                        {
                            System.Diagnostics.Process.Start(Path.GetTempPath() + "\\" + fileName);
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Không mở được File \n" + Path.GetTempPath() + "\\" + fileName, "Thông báo");
                        }
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("File " + Path.GetTempPath() + "\\" + fileName + " đang được mở bằng một ứng dụng khác.\nHãy chọn file khác!", "Thông báo");
                }
            }
        }

        private void ExportData2Excel(string _Title, DataTable dt, string _FileName)
        {
            if (dt.Columns.Contains("RowNumber"))
                dt.Columns["RowNumber"].Caption = "STT";

            if (dt.Columns.Contains("Employee_LastName"))
                dt.Columns["Employee_LastName"].Caption = "Họ và tên đệm";

            if (dt.Columns.Contains("Employee_FirstName"))
                dt.Columns["Employee_FirstName"].Caption = "Tên";

            if (dt.Columns.Contains("Employee_FullName"))
                dt.Columns["Employee_FullName"].Caption = "Họ và tên";

            if (dt.Columns.Contains("Employee_NativeCountry"))
                dt.Columns["Employee_NativeCountry"].Caption = "Nguyên quán";

            if (dt.Columns.Contains("Employee_DateOfBirth"))
                dt.Columns["Employee_DateOfBirth"].Caption = "Ngày sinh";

            if (dt.Columns.Contains("Employee_Sex"))
                dt.Columns["Employee_Sex"].Caption = "Giới tính";

            if (dt.Columns.Contains("Employee_PlaceOfBirth"))
                dt.Columns["Employee_PlaceOfBirth"].Caption = "Nơi sinh";

            if (dt.Columns.Contains("Employee_Code"))
                dt.Columns["Employee_Code"].Caption = "Mã NV";

            if (dt.Columns.Contains("National_Name"))
                dt.Columns["National_Name"].Caption = "Quốc tịch";

            if (dt.Columns.Contains("Employee_Type"))
                dt.Columns["Employee_Type"].Caption = "Loại nhân viên";

            if (dt.Columns.Contains("Standard_Name"))
                dt.Columns["Standard_Name"].Caption = "Trình độ học vấn";

            if (dt.Columns.Contains("Employee_Phone"))
                dt.Columns["Employee_Phone"].Caption = "ĐT";

            if (dt.Columns.Contains("PD_PositionFactor"))
                dt.Columns["PD_PositionFactor"].Caption = "HSPC chức vụ";

            if (dt.Columns.Contains("PD_OverFactor"))
                dt.Columns["PD_OverFactor"].Caption = "HSPC TNVK";

            if (dt.Columns.Contains("PD_JobFactor"))
                dt.Columns["PD_JobFactor"].Caption = "HSPC nghề";

            if (dt.Columns.Contains("PD_AreaFactor"))
                dt.Columns["PD_AreaFactor"].Caption = "HSPC khu vực";

            if (dt.Columns.Contains("PD_TelephoneAllowance"))
                dt.Columns["PD_TelephoneAllowance"].Caption = "Phụ cấp điện thoại";

            if (dt.Columns.Contains("PD_LunchAllowance"))
                dt.Columns["PD_LunchAllowance"].Caption = "Phụ cấp cơm trưa";

            if (dt.Columns.Contains("PD_OtherAllowance"))
                dt.Columns["PD_OtherAllowance"].Caption = "Phụ cấp khác";

            if (dt.Columns.Contains("PD_BasicFactor"))
                dt.Columns["PD_BasicFactor"].Caption = "Hệ số lương";

            if (dt.Columns.Contains("PD_BasicSalary"))
                dt.Columns["PD_BasicSalary"].Caption = "Lương cơ bản";

            if (dt.Columns.Contains("PD_TotalSalary"))
                dt.Columns["PD_TotalSalary"].Caption = "Lương thực nhận";

            if (dt.Columns.Contains("Employee_MedicalNo"))
                dt.Columns["Employee_MedicalNo"].Caption = "Số thẻ BHYT";

            if (dt.Columns.Contains("Employee_Description"))
                dt.Columns["Employee_Description"].Caption = "Ghi chú";

            if (dt.Columns.Contains("GradeType_Name"))
                dt.Columns["GradeType_Name"].Caption = "Loại công chức";

            if (dt.Columns.Contains("Position_Name"))
                dt.Columns["Position_Name"].Caption = "Chức vụ";

            if (dt.Columns.Contains("Grade_Name"))
                dt.Columns["Grade_Name"].Caption = "Ngạch/Chức danh";

            if (dt.Columns.Contains("ContractType_Name"))
                dt.Columns["ContractType_Name"].Caption = "Loại HĐ";

            if (dt.Columns.Contains("LC_No"))
                dt.Columns["LC_No"].Caption = "Số HĐ hiện tại";

            if (dt.Columns.Contains("LC_Date"))
                dt.Columns["LC_Date"].Caption = "Ngày ký HĐ hiện tại";

            if (dt.Columns.Contains("LC_FinishDate"))
                dt.Columns["LC_FinishDate"].Caption = "Ngày hết hạn HĐ";

            if (dt.Columns.Contains("MaritalStatus_Name"))
                dt.Columns["MaritalStatus_Name"].Caption = "Tình trạng hôn nhân";

            if (dt.Columns.Contains("Religion_Name"))
                dt.Columns["Religion_Name"].Caption = "Tôn giáo";

            if (dt.Columns.Contains("Ethnic_Name"))
                dt.Columns["Ethnic_Name"].Caption = "Dân tộc";

            if (dt.Columns.Contains("Employee_Culture"))
                dt.Columns["Employee_Culture"].Caption = "Trình độ văn hóa";

            if (dt.Columns.Contains("Employee_BankAccountNo"))
                dt.Columns["Employee_BankAccountNo"].Caption = "Số TK ngân hàng";

            if (dt.Columns.Contains("Employee_BankName"))
                dt.Columns["Employee_BankName"].Caption = "Ngân hàng";

            if (dt.Columns.Contains("Employee_Specialist"))
                dt.Columns["Employee_Specialist"].Caption = "Chuyên ngành";

            if (dt.Columns.Contains("PD_Job"))
                dt.Columns["PD_Job"].Caption = "Nghề nghiệp";

            if (dt.Columns.Contains("Branch_Name"))
                dt.Columns["Branch_Name"].Caption = "Đơn vị";

            if (dt.Columns.Contains("Employee_StartDate"))
                dt.Columns["Employee_StartDate"].Caption = "Ngày vào Cty";

            if (dt.Columns.Contains("Employee_IDCardNo"))
                dt.Columns["Employee_IDCardNo"].Caption = "Số CMT";

            if (dt.Columns.Contains("Employee_IDCardIssueDate"))
                dt.Columns["Employee_IDCardIssueDate"].Caption = "Ngày cấp";

            if (dt.Columns.Contains("Employee_IDCardIssueAuthority"))
                dt.Columns["Employee_IDCardIssueAuthority"].Caption = "Nơi cấp";

            if (dt.Columns.Contains("Employee_SIBookNo"))
                dt.Columns["Employee_SIBookNo"].Caption = "Số sổ BH";

            if (dt.Columns.Contains("Employee_SIBookIssueDate"))
                dt.Columns["Employee_SIBookIssueDate"].Caption = "Ngày cấp";

            if (dt.Columns.Contains("Employee_SIBookIssueAuthority"))
                dt.Columns["Employee_SIBookIssueAuthority"].Caption = "Nơi cấp";

            if (dt.Columns.Contains("Employee_MedicalCard"))
                dt.Columns["Employee_MedicalCard"].Caption = "Số thẻ BHYT";

            if (dt.Columns.Contains("Employee_MedicalDate"))
                dt.Columns["Employee_MedicalDate"].Caption = "Ngày cấp";

            if (dt.Columns.Contains("Employee_MedicalPlace"))
                dt.Columns["Employee_MedicalPlace"].Caption = "Nơi khám BHYT";

            if (dt.Columns.Contains("Employee_PartyDate"))
                dt.Columns["Employee_PartyDate"].Caption = "Ngày vào đảng";

            if (dt.Columns.Contains("Employee_ArmyFromDate"))
                dt.Columns["Employee_ArmyFromDate"].Caption = "Ngày nhập ngũ";

            if (dt.Columns.Contains("Employee_ArmyToDate"))
                dt.Columns["Employee_ArmyToDate"].Caption = "Ngày xuất ngũ";

            if (dt.Columns.Contains("Employee_ArmyPosition"))
                dt.Columns["Employee_ArmyPosition"].Caption = "Cvụ quân đội cao nhất";

            if (dt.Columns.Contains("Department_Name"))
                dt.Columns["Department_Name"].Caption = "Phòng ban";

            if (dt.Columns.Contains("Employee_Address"))
                dt.Columns["Employee_Address"].Caption = "Địa chỉ";

            if (dt.Columns.Contains("Level_Name"))
                dt.Columns["Level_Name"].Caption = "Bậc";

            ReadExcelFile.exportToExcel(_Title, dt, _FileName);
        }

        private void mnuPrintSalaryDepartmentOne_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedRows.Count > 0)
            {
                employeeID = Convert.ToInt32(dgvEmployeeList.SelectedRows[0].Cells["Employee_ID"].Value);
                if (listRole.Update || listRole.View)
                {
                    frmPreviewReport f = new frmPreviewReport("TangLuong_ThuyenChuyen_1", new string[] { employeeID.ToString(), "true" });
                    f.Show(this);
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void mnuPrintSalaryDepartmentAll_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedRows.Count > 0)
            {

                if (listRole.Update || listRole.View)
                {
                    frmPreviewReport f = new frmPreviewReport("TangLuong_ThuyenChuyen_ALL", new string[] { branch_ID.ToString() });
                    f.Show(this);
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

        }

        private void mnuLiLichCanBo_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedCells[0] != null)
            {
                if (listRole.Update || listRole.View)
                {
                    employeeID = Convert.ToInt32(dgvEmployeeList.Rows[dgvEmployeeList.SelectedCells[0].RowIndex].Cells["Employee_ID"].Value);

                    frmPreviewReport f = new frmPreviewReport("LiLichCanBo", new string[] { employeeID.ToString() });
                    f.Show(this);
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void mnuContract_Click(object sender, EventArgs e)
        {
            DateTime _LCDate = DateTime.MinValue;

            if (dgvEmployeeList.SelectedCells[0] != null)
            {
                _EmpID = Convert.ToInt32(dgvEmployeeList.Rows[dgvEmployeeList.SelectedCells[0].RowIndex].Cells["Employee_ID"].Value);
                _LCInfo = new LabourContractInfo();
                _LCInfo = wcfLC.LabourContract_GetWithEmployee_LCActive(_EmpID);
                if (_LCInfo != null)
                {
                    _LCID = _LCInfo.ID;
                    _LCDate = _LCInfo.EndProbationPeriod;
                    frmPreviewReport f;
                    if (DateTime.Compare(_LCDate, DateTime.Now.Date) > 0)
                        f = new frmPreviewReport("LabourProbationContract", new string[] { _LCID.ToString() });
                    else
                        f = new frmPreviewReport("LabourContract", new string[] { _LCID.ToString() });
                    f.ShowDialog();
                }
                else
                    MessageBox.Show("Chưa có hợp đồng lao động", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void mnuContractList_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedCells[0] != null)
            {
                _EmpID = Convert.ToInt32(dgvEmployeeList.Rows[dgvEmployeeList.SelectedCells[0].RowIndex].Cells["Employee_ID"].Value);
                _LCInfo = new LabourContractInfo();
                _LCInfo = wcfLC.LabourContract_GetWithEmployee_LCActive(_EmpID);
                if (_LCInfo != null)
                {
                    _LCID = _LCInfo.ID;
                    frmPreviewReport f = new frmPreviewReport("LabourContractMenu", new string[] { _LCID.ToString() });
                    f.ShowDialog();
                }
                else
                    MessageBox.Show("Chưa có hợp đồng lao động", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void mnuSalary_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedCells[0] != null)
            {
                _EmpID = Convert.ToInt32(dgvEmployeeList.Rows[dgvEmployeeList.SelectedCells[0].RowIndex].Cells["Employee_ID"].Value);
                frmPreviewReport f = new frmPreviewReport("SalaryAgreement", new string[] { _EmpID.ToString() });
                f.ShowDialog();
            }
        }

        private void mnuConfirmIns_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedCells[0] != null)
            {
                _EmpID = Convert.ToInt32(dgvEmployeeList.Rows[dgvEmployeeList.SelectedCells[0].RowIndex].Cells["Employee_ID"].Value);
                frmPreviewReport f = new frmPreviewReport("XacNhanDongBH", new string[] { _EmpID.ToString() });
                f.ShowDialog();
            }
        }

        private void mnuWorkingBachground_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedCells[0] != null)
            {
                _EmpID = Convert.ToInt32(dgvEmployeeList.Rows[dgvEmployeeList.SelectedCells[0].RowIndex].Cells["Employee_ID"].Value);
                frmPreviewReport f = new frmPreviewReport("kingnghiemlamviec", new string[] { _EmpID.ToString() });
                f.ShowDialog();
            }

        }

        private void btnExpA02_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedCells[0] != null)
            {
                _EmpID = Convert.ToInt32(dgvEmployeeList.Rows[dgvEmployeeList.SelectedCells[0].RowIndex].Cells["Employee_ID"].Value);
                string Type = "InToKhaiBHXH_A02_TS";
                frmPreviewReport f = new frmPreviewReport(_EmpID, Type);
                f.Show(this);
            }
        }

        private void btnExpTK01_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedCells[0] != null)
            {
                _EmpID = Convert.ToInt32(dgvEmployeeList.Rows[dgvEmployeeList.SelectedCells[0].RowIndex].Cells["Employee_ID"].Value);

                string Type = "InToKhaiBHXH_TK1_TS";
                frmPreviewReport f = new frmPreviewReport(_EmpID, Type);
                f.Show(this);
            }
        }

        private void cmdToggle_Click(object sender, EventArgs e)
        {
            splitContainer1.Panel1Collapsed = !splitContainer1.Panel1Collapsed;
            cmdToggle.Image = splitContainer1.Panel1Collapsed ? Properties.Resources.right16 : Properties.Resources.left16;
        }

        private void pager_PageIndex_Changed(int pageIndex)
        {
            FormGlobals.App_ProgressShow(delegate()
            {
                LoadData();
            }, "");
        }
    }
}

